package com.yfq.springframework.beans;

/**
 * @author 姚凤桥
 * @date 2022/11/13 14:11
 * @description
 */
public abstract class AbstractBeanFactory extends DefaultSingletonBeanRegistry implements BeanFactory {

    @Override
    public Object getBean(String beanName) throws InstantiationException, IllegalAccessException {
        Object bean = getSingletonBean(beanName);
        if (bean != null) {
            return bean;
        }

        BeanDefinition beanDefinition = getBeanDefinition(beanName);
        return createBean(beanName, beanDefinition);
    }

    /**
     * 获取beanDefinition
     *
     * @param beanName ...
     * @return ...
     */
    protected abstract BeanDefinition getBeanDefinition(String beanName);

    /**
     * 创建bean
     *
     * @param beanName       ...
     * @param beanDefinition ...
     * @return ...
     * @throws InstantiationException ...
     * @throws IllegalAccessException ...
     */
    protected abstract Object createBean(String beanName, BeanDefinition beanDefinition) throws InstantiationException, IllegalAccessException;

}
